# Maintainer: Leandro Nini <drfiemost@email.it>

_realname=libsidplayfp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.3.0
pkgrel=1
pkgdesc="A library to play Commodore 64 music (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/libsidplayfp/libsidplayfp"
license=("GPL")
depends=("${MINGW_PACKAGE_PREFIX}-libftdi"
          "${MINGW_PACKAGE_PREFIX}-libgcrypt")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=("https://github.com/libsidplayfp/libsidplayfp/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('30b91b2b9a3a644533c8e4e926724efb8b4cf06aded1fcec4c68aa21159b8673')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --enable-hardsid

  make
}

check() {
  cd "${srcdir}/build-${CARCH}"
  make check
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/README ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
